package cn.seocoo.platform.common.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.reflect.Field;

/**
 * created by L on 2019/10/23 3:33 下午
 **/
public class ObjUtils {
    private static final Logger logger = LoggerFactory.getLogger(ObjUtils.class);

    /***
     * @Author L
     * @Description 判断对象属性值是否为空
     * @Date 3:29 下午 2019/10/23
     * @Param [object, obj]
     * @return cn.seocoo.platform.api.util.JSONResult
     **/
    /***
     * @Author L
     * @Description 判断对象属性值是否为空
     * @Date 3:29 下午 2019/10/23
     * @Param [object, obj]
     * @return cn.seocoo.platform.api.util.JSONResult
     **/
    public static String checkObjAllFieldsIsNull(Object object,String value) {
        String res = null;
        if (null == object) {
            res = "object不能为空";
        }

        String [] temp = value.split(",");
        try {
            tp: for (Field f : object.getClass().getDeclaredFields()) {
                f.setAccessible(true);
                for (String s : temp) {
                    if (f.getName().equals(s)){
                        if (f.get(object) == null || StringUtils.isNull(f.get(object))) {
                            logger.warn(f.getName() + "不能为空");
                            res =  f.getName() + "不能为空";
                            break tp;
                        }
                    } continue;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return res;
    }
}
